1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /**
18  * @addtogroup Sensor
19  * @{
20  */
21 
22 /**
23  * @file sensor.h
24  */
25 
26 module android.ndk.sensor;
27 
28 import core.stdc.math;
29 import core.stdc.stdint;
30 import core.sys.posix.sys.types;
31 
32 import arsd.jni;
33 import android.ndk;
34 
35 extern (C):
36 nothrow:
37 @nogc:
38 
39 /******************************************************************
40  *
41  * IMPORTANT NOTICE:
42  *
43  *   This file is part of Android's set of stable system headers
44  *   exposed by the Android NDK (Native Development Kit).
45  *
46  *   Third-party source AND binary code relies on the definitions
47  *   here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
48  *
49  *   - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
50  *   - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
51  *   - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
52  *   - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
53  */
54 
55 /**
56  * Structures and functions to receive and process sensor events in
57  * native code.
58  *
59  */
60 
61 enum ASENSOR_RESOLUTION_INVALID = float.nan;
62 enum ASENSOR_FIFO_COUNT_INVALID = -1;
63 enum ASENSOR_DELAY_INVALID = INT32_MIN;
64 enum ASENSOR_INVALID = -1;
65 
66 /* (Keep in sync with hardware/sensors-base.h and Sensor.java.) */
67 
68 /**
69  * Sensor types.
70  *
71  * See
72  * [android.hardware.SensorEvent#values](https://developer.android.com/reference/android/hardware/SensorEvent.html#values)
73  * for detailed explanations of the data returned for each of these types.
74  */
75 enum
76 {
77     /**
78      * Invalid sensor type. Returned by {@link ASensor_getType} as error value.
79      */
80     ASENSOR_TYPE_INVALID = -1,
81     /**
82      * {@link ASENSOR_TYPE_ACCELEROMETER}
83      * reporting-mode: continuous
84      *
85      *  All values are in SI units (m/s^2) and measure the acceleration of the
86      *  device minus the force of gravity.
87      */
88     ASENSOR_TYPE_ACCELEROMETER = 1,
89     /**
90      * {@link ASENSOR_TYPE_MAGNETIC_FIELD}
91      * reporting-mode: continuous
92      *
93      *  All values are in micro-Tesla (uT) and measure the geomagnetic
94      *  field in the X, Y and Z axis.
95      */
96     ASENSOR_TYPE_MAGNETIC_FIELD = 2,
97     /**
98      * {@link ASENSOR_TYPE_GYROSCOPE}
99      * reporting-mode: continuous
100      *
101      *  All values are in radians/second and measure the rate of rotation
102      *  around the X, Y and Z axis.
103      */
104     ASENSOR_TYPE_GYROSCOPE = 4,
105     /**
106      * {@link ASENSOR_TYPE_LIGHT}
107      * reporting-mode: on-change
108      *
109      * The light sensor value is returned in SI lux units.
110      */
111     ASENSOR_TYPE_LIGHT = 5,
112     /**
113      * {@link ASENSOR_TYPE_PRESSURE}
114      *
115      * The pressure sensor value is returned in hPa (millibar).
116      */
117     ASENSOR_TYPE_PRESSURE = 6,
118     /**
119      * {@link ASENSOR_TYPE_PROXIMITY}
120      * reporting-mode: on-change
121      *
122      * The proximity sensor which turns the screen off and back on during calls is the
123      * wake-up proximity sensor. Implement wake-up proximity sensor before implementing
124      * a non wake-up proximity sensor. For the wake-up proximity sensor set the flag
125      * SENSOR_FLAG_WAKE_UP.
126      * The value corresponds to the distance to the nearest object in centimeters.
127      */
128     ASENSOR_TYPE_PROXIMITY = 8,
129     /**
130      * {@link ASENSOR_TYPE_GRAVITY}
131      *
132      * All values are in SI units (m/s^2) and measure the direction and
133      * magnitude of gravity. When the device is at rest, the output of
134      * the gravity sensor should be identical to that of the accelerometer.
135      */
136     ASENSOR_TYPE_GRAVITY = 9,
137     /**
138      * {@link ASENSOR_TYPE_LINEAR_ACCELERATION}
139      * reporting-mode: continuous
140      *
141      *  All values are in SI units (m/s^2) and measure the acceleration of the
142      *  device not including the force of gravity.
143      */
144     ASENSOR_TYPE_LINEAR_ACCELERATION = 10,
145     /**
146      * {@link ASENSOR_TYPE_ROTATION_VECTOR}
147      */
148     ASENSOR_TYPE_ROTATION_VECTOR = 11,
149     /**
150      * {@link ASENSOR_TYPE_RELATIVE_HUMIDITY}
151      *
152      * The relative humidity sensor value is returned in percent.
153      */
154     ASENSOR_TYPE_RELATIVE_HUMIDITY = 12,
155     /**
156      * {@link ASENSOR_TYPE_AMBIENT_TEMPERATURE}
157      *
158      * The ambient temperature sensor value is returned in Celcius.
159      */
160     ASENSOR_TYPE_AMBIENT_TEMPERATURE = 13,
161     /**
162      * {@link ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED}
163      */
164     ASENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED = 14,
165     /**
166      * {@link ASENSOR_TYPE_GAME_ROTATION_VECTOR}
167      */
168     ASENSOR_TYPE_GAME_ROTATION_VECTOR = 15,
169     /**
170      * {@link ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED}
171      */
172     ASENSOR_TYPE_GYROSCOPE_UNCALIBRATED = 16,
173     /**
174      * {@link ASENSOR_TYPE_SIGNIFICANT_MOTION}
175      */
176     ASENSOR_TYPE_SIGNIFICANT_MOTION = 17,
177     /**
178      * {@link ASENSOR_TYPE_STEP_DETECTOR}
179      */
180     ASENSOR_TYPE_STEP_DETECTOR = 18,
181     /**
182      * {@link ASENSOR_TYPE_STEP_COUNTER}
183      */
184     ASENSOR_TYPE_STEP_COUNTER = 19,
185     /**
186      * {@link ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR}
187      */
188     ASENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR = 20,
189     /**
190      * {@link ASENSOR_TYPE_HEART_RATE}
191      */
192     ASENSOR_TYPE_HEART_RATE = 21,
193     /**
194      * {@link ASENSOR_TYPE_POSE_6DOF}
195      */
196     ASENSOR_TYPE_POSE_6DOF = 28,
197     /**
198      * {@link ASENSOR_TYPE_STATIONARY_DETECT}
199      */
200     ASENSOR_TYPE_STATIONARY_DETECT = 29,
201     /**
202      * {@link ASENSOR_TYPE_MOTION_DETECT}
203      */
204     ASENSOR_TYPE_MOTION_DETECT = 30,
205     /**
206      * {@link ASENSOR_TYPE_HEART_BEAT}
207      */
208     ASENSOR_TYPE_HEART_BEAT = 31,
209     /**
210      * This sensor type is for delivering additional sensor information aside
211      * from sensor event data.
212      *
213      * Additional information may include:
214      *     - {@link ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE}
215      *     - {@link ASENSOR_ADDITIONAL_INFO_SAMPLING}
216      *     - {@link ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT}
217      *     - {@link ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY}
218      *     - {@link ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION}
219      *
220      * This type will never bind to a sensor. In other words, no sensor in the
221      * sensor list can have the type {@link ASENSOR_TYPE_ADDITIONAL_INFO}.
222      *
223      * If a device supports the sensor additional information feature, it will
224      * report additional information events via {@link ASensorEvent} and will
225      * have {@link ASensorEvent#type} set to
226      * {@link ASENSOR_TYPE_ADDITIONAL_INFO} and {@link ASensorEvent#sensor} set
227      * to the handle of the reporting sensor.
228      *
229      * Additional information reports consist of multiple frames ordered by
230      * {@link ASensorEvent#timestamp}. The first frame in the report will have
231      * a {@link AAdditionalInfoEvent#type} of
232      * {@link ASENSOR_ADDITIONAL_INFO_BEGIN}, and the last frame in the report
233      * will have a {@link AAdditionalInfoEvent#type} of
234      * {@link ASENSOR_ADDITIONAL_INFO_END}.
235      *
236      */
237     ASENSOR_TYPE_ADDITIONAL_INFO = 33,
238     /**
239      * {@link ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT}
240      */
241     ASENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT = 34,
242     /**
243      * {@link ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED}
244      */
245     ASENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 35
246 }
247 
248 /**
249  * Sensor accuracy measure.
250  */
251 enum
252 {
253     /** no contact */
254     ASENSOR_STATUS_NO_CONTACT = -1,
255     /** unreliable */
256     ASENSOR_STATUS_UNRELIABLE = 0,
257     /** low accuracy */
258     ASENSOR_STATUS_ACCURACY_LOW = 1,
259     /** medium accuracy */
260     ASENSOR_STATUS_ACCURACY_MEDIUM = 2,
261     /** high accuracy */
262     ASENSOR_STATUS_ACCURACY_HIGH = 3
263 }
264 
265 /**
266  * Sensor Reporting Modes.
267  */
268 enum
269 {
270     /** invalid reporting mode */
271     AREPORTING_MODE_INVALID = -1,
272     /** continuous reporting */
273     AREPORTING_MODE_CONTINUOUS = 0,
274     /** reporting on change */
275     AREPORTING_MODE_ON_CHANGE = 1,
276     /** on shot reporting */
277     AREPORTING_MODE_ONE_SHOT = 2,
278     /** special trigger reporting */
279     AREPORTING_MODE_SPECIAL_TRIGGER = 3
280 }
281 
282 /**
283  * Sensor Direct Report Rates.
284  */
285 enum
286 {
287     /** stopped */
288     ASENSOR_DIRECT_RATE_STOP = 0,
289     /** nominal 50Hz */
290     ASENSOR_DIRECT_RATE_NORMAL = 1,
291     /** nominal 200Hz */
292     ASENSOR_DIRECT_RATE_FAST = 2,
293     /** nominal 800Hz */
294     ASENSOR_DIRECT_RATE_VERY_FAST = 3
295 }
296 
297 /**
298  * Sensor Direct Channel Type.
299  */
300 enum
301 {
302     /** shared memory created by ASharedMemory_create */
303     ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY = 1,
304     /** AHardwareBuffer */
305     ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER = 2
306 }
307 
308 /**
309  * Sensor Additional Info Types.
310  *
311  * Used to populate {@link AAdditionalInfoEvent#type}.
312  */
313 enum
314 {
315     /** Marks the beginning of additional information frames */
316     ASENSOR_ADDITIONAL_INFO_BEGIN = 0,
317 
318     /** Marks the end of additional information frames */
319     ASENSOR_ADDITIONAL_INFO_END = 1,
320 
321     /**
322      * Estimation of the delay that is not tracked by sensor timestamps. This
323      * includes delay introduced by sensor front-end filtering, data transport,
324      * etc.
325      * float[2]: delay in seconds, standard deviation of estimated value
326      */
327     ASENSOR_ADDITIONAL_INFO_UNTRACKED_DELAY = 0x10000,
328 
329     /** float: Celsius temperature */
330     ASENSOR_ADDITIONAL_INFO_INTERNAL_TEMPERATURE = 65537,
331 
332     /**
333      * First three rows of a homogeneous matrix, which represents calibration to
334      * a three-element vector raw sensor reading.
335      * float[12]: 3x4 matrix in row major order
336      */
337     ASENSOR_ADDITIONAL_INFO_VEC3_CALIBRATION = 65538,
338 
339     /**
340      * Location and orientation of sensor element in the device frame: origin is
341      * the geometric center of the mobile device screen surface; the axis
342      * definition corresponds to Android sensor definitions.
343      * float[12]: 3x4 matrix in row major order
344      */
345     ASENSOR_ADDITIONAL_INFO_SENSOR_PLACEMENT = 65539,
346 
347     /**
348      * float[2]: raw sample period in seconds,
349      *           standard deviation of sampling period
350      */
351     ASENSOR_ADDITIONAL_INFO_SAMPLING = 65540
352 }
353 
354 /*
355  * A few useful constants
356  */
357 
358 /** Earth's gravity in m/s^2 */
359 enum ASENSOR_STANDARD_GRAVITY = 9.80665f;
360 /** Maximum magnetic field on Earth's surface in uT */
361 enum ASENSOR_MAGNETIC_FIELD_EARTH_MAX = 60.0f;
362 /** Minimum magnetic field on Earth's surface in uT*/
363 enum ASENSOR_MAGNETIC_FIELD_EARTH_MIN = 30.0f;
364 
365 /**
366  * A sensor event.
367  */
368 
369 /* NOTE: changes to these structs have to be backward compatible */
370 struct ASensorVector
371 {
372     union
373     {
374         float[3] v;
375 
376         struct
377         {
378             float x;
379             float y;
380             float z;
381         }
382 
383         struct
384         {
385             float azimuth;
386             float pitch;
387             float roll;
388         }
389     }
390 
391     byte status;
392     ubyte[3] reserved;
393 }
394 
395 struct AMetaDataEvent
396 {
397     int what;
398     int sensor;
399 }
400 
401 struct AUncalibratedEvent
402 {
403     union
404     {
405         float[3] uncalib;
406 
407         struct
408         {
409             float x_uncalib;
410             float y_uncalib;
411             float z_uncalib;
412         }
413     }
414 
415     union
416     {
417         float[3] bias;
418 
419         struct
420         {
421             float x_bias;
422             float y_bias;
423             float z_bias;
424         }
425     }
426 }
427 
428 struct AHeartRateEvent
429 {
430     float bpm;
431     byte status;
432 }
433 
434 struct ADynamicSensorEvent
435 {
436     int connected;
437     int handle;
438 }
439 
440 struct AAdditionalInfoEvent
441 {
442     int type;
443     int serial;
444 
445     union
446     {
447         int[14] data_int32;
448         float[14] data_float;
449     }
450 }
451 
452 /* NOTE: changes to this struct has to be backward compatible */
453 struct ASensorEvent
454 {
455     int version_; /* sizeof(struct ASensorEvent) */
456     int sensor;
457     int type;
458     int reserved0;
459     long timestamp;
460 
461     union
462     {
463         union
464         {
465             float[16] data;
466             ASensorVector vector;
467             ASensorVector acceleration;
468             ASensorVector magnetic;
469             float temperature;
470             float distance;
471             float light;
472             float pressure;
473             float relative_humidity;
474             AUncalibratedEvent uncalibrated_gyro;
475             AUncalibratedEvent uncalibrated_magnetic;
476             AMetaDataEvent meta_data;
477             AHeartRateEvent heart_rate;
478             ADynamicSensorEvent dynamic_sensor_meta;
479             AAdditionalInfoEvent additional_info;
480         }
481 
482         union _Anonymous_0
483         {
484             ulong[8] data;
485             ulong step_counter;
486         }
487 
488         _Anonymous_0 u64;
489     }
490 
491     uint flags;
492     int[3] reserved1;
493 }
494 
495 struct ASensorManager;
496 /**
497  * {@link ASensorManager} is an opaque type to manage sensors and
498  * events queues.
499  *
500  * {@link ASensorManager} is a singleton that can be obtained using
501  * ASensorManager_getInstance().
502  *
503  * This file provides a set of functions that uses {@link
504  * ASensorManager} to access and list hardware sensors, and
505  * create and destroy event queues:
506  * - ASensorManager_getSensorList()
507  * - ASensorManager_getDefaultSensor()
508  * - ASensorManager_getDefaultSensorEx()
509  * - ASensorManager_createEventQueue()
510  * - ASensorManager_destroyEventQueue()
511  */
512 
513 struct ASensorEventQueue;
514 /**
515  * {@link ASensorEventQueue} is an opaque type that provides access to
516  * {@link ASensorEvent} from hardware sensors.
517  *
518  * A new {@link ASensorEventQueue} can be obtained using ASensorManager_createEventQueue().
519  *
520  * This file provides a set of functions to enable and disable
521  * sensors, check and get events, and set event rates on a {@link
522  * ASensorEventQueue}.
523  * - ASensorEventQueue_enableSensor()
524  * - ASensorEventQueue_disableSensor()
525  * - ASensorEventQueue_hasEvents()
526  * - ASensorEventQueue_getEvents()
527  * - ASensorEventQueue_setEventRate()
528  * - ASensorEventQueue_requestAdditionalInfoEvents()
529  */
530 
531 struct ASensor;
532 /**
533  * {@link ASensor} is an opaque type that provides information about
534  * an hardware sensors.
535  *
536  * A {@link ASensor} pointer can be obtained using
537  * ASensorManager_getDefaultSensor(),
538  * ASensorManager_getDefaultSensorEx() or from a {@link ASensorList}.
539  *
540  * This file provides a set of functions to access properties of a
541  * {@link ASensor}:
542  * - ASensor_getName()
543  * - ASensor_getVendor()
544  * - ASensor_getType()
545  * - ASensor_getResolution()
546  * - ASensor_getMinDelay()
547  * - ASensor_getFifoMaxEventCount()
548  * - ASensor_getFifoReservedEventCount()
549  * - ASensor_getStringType()
550  * - ASensor_getReportingMode()
551  * - ASensor_isWakeUpSensor()
552  * - ASensor_getHandle()
553  */
554 /**
555  * {@link ASensorRef} is a type for constant pointers to {@link ASensor}.
556  *
557  * This is used to define entry in {@link ASensorList} arrays.
558  */
559 alias ASensorRef = const(ASensor)*;
560 /**
561  * {@link ASensorList} is an array of reference to {@link ASensor}.
562  *
563  * A {@link ASensorList} can be initialized using ASensorManager_getSensorList().
564  */
565 alias ASensorList = const(ASensor*)*;
566 
567 /*****************************************************************************/
568 
569 /**
570  * Get a reference to the sensor manager. ASensorManager is a singleton
571  * per package as different packages may have access to different sensors.
572  *
573  * Deprecated: Use ASensorManager_getInstanceForPackage(const char*) instead.
574  *
575  * Example:
576  *
577  *     ASensorManager* sensorManager = ASensorManager_getInstance();
578  *
579  */
580 ASensorManager* ASensorManager_getInstance ();
581 
582 /**
583  * Get a reference to the sensor manager. ASensorManager is a singleton
584  * per package as different packages may have access to different sensors.
585  *
586  * Example:
587  *
588  *     ASensorManager* sensorManager = ASensorManager_getInstanceForPackage("foo.bar.baz");
589  *
590  */
591 ASensorManager* ASensorManager_getInstanceForPackage (const(char)* packageName);
592 
593 /**
594  * Returns the list of available sensors.
595  */
596 int ASensorManager_getSensorList (ASensorManager* manager, ASensorList* list);
597 
598 /**
599  * Returns the default sensor for the given type, or NULL if no sensor
600  * of that type exists.
601  */
602 const(ASensor)* ASensorManager_getDefaultSensor (ASensorManager* manager, int type);
603 
604 /**
605  * Returns the default sensor with the given type and wakeUp properties or NULL if no sensor
606  * of this type and wakeUp properties exists.
607  */
608 const(ASensor)* ASensorManager_getDefaultSensorEx (ASensorManager* manager, int type, bool wakeUp);
609 
610 /**
611  * Creates a new sensor event queue and associate it with a looper.
612  *
613  * "ident" is a identifier for the events that will be returned when
614  * calling ALooper_pollOnce(). The identifier must be >= 0, or
615  * ALOOPER_POLL_CALLBACK if providing a non-NULL callback.
616  */
617 ASensorEventQueue* ASensorManager_createEventQueue (
618     ASensorManager* manager,
619     ALooper* looper,
620     int ident,
621     ALooper_callbackFunc callback,
622     void* data);
623 
624 /**
625  * Destroys the event queue and free all resources associated to it.
626  */
627 int ASensorManager_destroyEventQueue (ASensorManager* manager, ASensorEventQueue* queue);
628 
629 /**
630  * Create direct channel based on shared memory
631  *
632  * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY} to be used
633  * for configuring sensor direct report.
634  *
635  * \param manager the {@link ASensorManager} instance obtained from
636  *                {@link ASensorManager_getInstanceForPackage}.
637  * \param fd      file descriptor representing a shared memory created by
638  *                {@link ASharedMemory_create}
639  * \param size    size to be used, must be less or equal to size of shared memory.
640  *
641  * \return a positive integer as a channel id to be used in
642  *         {@link ASensorManager_destroyDirectChannel} and
643  *         {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
644  */
645 int ASensorManager_createSharedMemoryDirectChannel (ASensorManager* manager, int fd, size_t size);
646 
647 /**
648  * Create direct channel based on AHardwareBuffer
649  *
650  * Create a direct channel of {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER} type to be used
651  * for configuring sensor direct report.
652  *
653  * \param manager the {@link ASensorManager} instance obtained from
654  *                {@link ASensorManager_getInstanceForPackage}.
655  * \param buffer  {@link AHardwareBuffer} instance created by {@link AHardwareBuffer_allocate}.
656  * \param size    the intended size to be used, must be less or equal to size of buffer.
657  *
658  * \return a positive integer as a channel id to be used in
659  *         {@link ASensorManager_destroyDirectChannel} and
660  *         {@link ASensorManager_configureDirectReport}, or value less or equal to 0 for failures.
661  */
662 int ASensorManager_createHardwareBufferDirectChannel (
663     ASensorManager* manager,
664     const(AHardwareBuffer)* buffer,
665     size_t size);
666 
667 /**
668  * Destroy a direct channel
669  *
670  * Destroy a direct channel previously created using {@link ASensorManager_createDirectChannel}.
671  * The buffer used for creating direct channel does not get destroyed with
672  * {@link ASensorManager_destroy} and has to be close or released separately.
673  *
674  * \param manager the {@link ASensorManager} instance obtained from
675  *                {@link ASensorManager_getInstanceForPackage}.
676  * \param channelId channel id (a positive integer) returned from
677  *                  {@link ASensorManager_createSharedMemoryDirectChannel} or
678  *                  {@link ASensorManager_createHardwareBufferDirectChannel}.
679  */
680 void ASensorManager_destroyDirectChannel (ASensorManager* manager, int channelId);
681 
682 /**
683  * Configure direct report on channel
684  *
685  * Configure sensor direct report on a direct channel: set rate to value other than
686  * {@link ASENSOR_DIRECT_RATE_STOP} so that sensor event can be directly
687  * written into the shared memory region used for creating the buffer. It returns a positive token
688  * which can be used for identify sensor events from different sensors on success. Calling with rate
689  * {@link ASENSOR_DIRECT_RATE_STOP} will stop direct report of the sensor specified in the channel.
690  *
691  * To stop all active sensor direct report configured to a channel, set sensor to NULL and rate to
692  * {@link ASENSOR_DIRECT_RATE_STOP}.
693  *
694  * In order to successfully configure a direct report, the sensor has to support the specified rate
695  * and the channel type, which can be checked by {@link ASensor_getHighestDirectReportRateLevel} and
696  * {@link ASensor_isDirectChannelTypeSupported}, respectively.
697  *
698  * Example:
699  *
700  *     ASensorManager *manager = ...;
701  *     ASensor *sensor = ...;
702  *     int channelId = ...;
703  *
704  *     ASensorManager_configureDirectReport(manager, sensor, channel_id, ASENSOR_DIRECT_RATE_FAST);
705  *
706  * \param manager   the {@link ASensorManager} instance obtained from
707  *                  {@link ASensorManager_getInstanceForPackage}.
708  * \param sensor    a {@link ASensor} to denote which sensor to be operate. It can be NULL if rate
709  *                  is {@link ASENSOR_DIRECT_RATE_STOP}, denoting stopping of all active sensor
710  *                  direct report.
711  * \param channelId channel id (a positive integer) returned from
712  *                  {@link ASensorManager_createSharedMemoryDirectChannel} or
713  *                  {@link ASensorManager_createHardwareBufferDirectChannel}.
714  *
715  * \return positive token for success or negative error code.
716  */
717 int ASensorManager_configureDirectReport (
718     ASensorManager* manager,
719     const(ASensor)* sensor,
720     int channelId,
721     int rate);
722 /* __ANDROID_API__ >= 26 */
723 
724 /*****************************************************************************/
725 
726 /**
727  * Enable the selected sensor with sampling and report parameters
728  *
729  * Enable the selected sensor at a specified sampling period and max batch report latency.
730  * To disable  sensor, use {@link ASensorEventQueue_disableSensor}.
731  *
732  * \param queue {@link ASensorEventQueue} for sensor event to be report to.
733  * \param sensor {@link ASensor} to be enabled.
734  * \param samplingPeriodUs sampling period of sensor in microseconds.
735  * \param maxBatchReportLatencyus maximum time interval between two batch of sensor events are
736  *                                delievered in microseconds. For sensor streaming, set to 0.
737  * \return 0 on success or a negative error code on failure.
738  */
739 int ASensorEventQueue_registerSensor (
740     ASensorEventQueue* queue,
741     const(ASensor)* sensor,
742     int samplingPeriodUs,
743     long maxBatchReportLatencyUs);
744 
745 /**
746  * Enable the selected sensor at default sampling rate.
747  *
748  * Start event reports of a sensor to specified sensor event queue at a default rate.
749  *
750  * \param queue {@link ASensorEventQueue} for sensor event to be report to.
751  * \param sensor {@link ASensor} to be enabled.
752  *
753  * \return 0 on success or a negative error code on failure.
754  */
755 int ASensorEventQueue_enableSensor (ASensorEventQueue* queue, const(ASensor)* sensor);
756 
757 /**
758  * Disable the selected sensor.
759  *
760  * Stop event reports from the sensor to specified sensor event queue.
761  *
762  * \param queue {@link ASensorEventQueue} to be changed
763  * \param sensor {@link ASensor} to be disabled
764  * \return 0 on success or a negative error code on failure.
765  */
766 int ASensorEventQueue_disableSensor (ASensorEventQueue* queue, const(ASensor)* sensor);
767 
768 /**
769  * Sets the delivery rate of events in microseconds for the given sensor.
770  *
771  * This function has to be called after {@link ASensorEventQueue_enableSensor}.
772  * Note that this is a hint only, generally event will arrive at a higher
773  * rate. It is an error to set a rate inferior to the value returned by
774  * ASensor_getMinDelay().
775  *
776  * \param queue {@link ASensorEventQueue} to which sensor event is delivered.
777  * \param sensor {@link ASensor} of which sampling rate to be updated.
778  * \param usec sensor sampling period (1/sampling rate) in microseconds
779  * \return 0 on sucess or a negative error code on failure.
780  */
781 int ASensorEventQueue_setEventRate (ASensorEventQueue* queue, const(ASensor)* sensor, int usec);
782 
783 /**
784  * Determine if a sensor event queue has pending event to be processed.
785  *
786  * \param queue {@link ASensorEventQueue} to be queried
787  * \return 1 if the queue has events; 0 if it does not have events;
788  *         or a negative value if there is an error.
789  */
790 int ASensorEventQueue_hasEvents (ASensorEventQueue* queue);
791 
792 /**
793  * Retrieve pending events in sensor event queue
794  *
795  * Retrieve next available events from the queue to a specified event array.
796  *
797  * \param queue {@link ASensorEventQueue} to get events from
798  * \param events pointer to an array of {@link ASensorEvents}.
799  * \param count max number of event that can be filled into array event.
800  * \return number of events returned on success; negative error code when
801  *         no events are pending or an error has occurred.
802  *
803  * Examples:
804  *
805  *     ASensorEvent event;
806  *     ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1);
807  *
808  *     ASensorEvent eventBuffer[8];
809  *     ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8);
810  *
811  */
812 ssize_t ASensorEventQueue_getEvents (ASensorEventQueue* queue, ASensorEvent* events, size_t count);
813 
814 /**
815  * Request that {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to be delivered on
816  * the given {@link ASensorEventQueue}.
817  *
818  * Sensor data events are always delivered to the {@ASensorEventQueue}.
819  *
820  * The {@link ASENSOR_TYPE_ADDITIONAL_INFO} events will be returned through
821  * {@link ASensorEventQueue_getEvents}. The client is responsible for checking
822  * {@link ASensorEvent#type} to determine the event type prior to handling of
823  * the event.
824  *
825  * The client must be tolerant of any value for
826  * {@link AAdditionalInfoEvent#type}, as new values may be defined in the future
827  * and may delivered to the client.
828  *
829  * \param queue {@link ASensorEventQueue} to configure
830  * \param enable true to request {@link ASENSOR_TYPE_ADDITIONAL_INFO} events,
831  *        false to stop receiving events
832  * \return 0 on success or a negative error code on failure
833  */
834 int ASensorEventQueue_requestAdditionalInfoEvents (ASensorEventQueue* queue, bool enable);
835 /* __ANDROID_API__ >= __ANDRDOID_API_Q__ */
836 
837 /*****************************************************************************/
838 
839 /**
840  * Returns this sensor's name (non localized)
841  */
842 const(char)* ASensor_getName (const(ASensor)* sensor);
843 
844 /**
845  * Returns this sensor's vendor's name (non localized)
846  */
847 const(char)* ASensor_getVendor (const(ASensor)* sensor);
848 
849 /**
850  * Return this sensor's type
851  */
852 int ASensor_getType (const(ASensor)* sensor);
853 
854 /**
855  * Returns this sensors's resolution
856  */
857 float ASensor_getResolution (const(ASensor)* sensor);
858 
859 /**
860  * Returns the minimum delay allowed between events in microseconds.
861  * A value of zero means that this sensor doesn't report events at a
862  * constant rate, but rather only when a new data is available.
863  */
864 int ASensor_getMinDelay (const(ASensor)* sensor);
865 
866 /**
867  * Returns the maximum size of batches for this sensor. Batches will often be
868  * smaller, as the hardware fifo might be used for other sensors.
869  */
870 int ASensor_getFifoMaxEventCount (const(ASensor)* sensor);
871 
872 /**
873  * Returns the hardware batch fifo size reserved to this sensor.
874  */
875 int ASensor_getFifoReservedEventCount (const(ASensor)* sensor);
876 
877 /**
878  * Returns this sensor's string type.
879  */
880 const(char)* ASensor_getStringType (const(ASensor)* sensor);
881 
882 /**
883  * Returns the reporting mode for this sensor. One of AREPORTING_MODE_* constants.
884  */
885 int ASensor_getReportingMode (const(ASensor)* sensor);
886 
887 /**
888  * Returns true if this is a wake up sensor, false otherwise.
889  */
890 bool ASensor_isWakeUpSensor (const(ASensor)* sensor);
891 /* __ANDROID_API__ >= 21 */
892 
893 /**
894  * Test if sensor supports a certain type of direct channel.
895  *
896  * \param sensor  a {@link ASensor} to denote the sensor to be checked.
897  * \param channelType  Channel type constant, either
898  *                     {@ASENSOR_DIRECT_CHANNEL_TYPE_SHARED_MEMORY}
899  *                     or {@link ASENSOR_DIRECT_CHANNEL_TYPE_HARDWARE_BUFFER}.
900  * \returns true if sensor supports the specified direct channel type.
901  */
902 bool ASensor_isDirectChannelTypeSupported (const(ASensor)* sensor, int channelType);
903 
904 /**
905  * Get the highest direct rate level that a sensor support.
906  *
907  * \param sensor  a {@link ASensor} to denote the sensor to be checked.
908  *
909  * \return a ASENSOR_DIRECT_RATE_... enum denoting the highest rate level supported by the sensor.
910  *         If return value is {@link ASENSOR_DIRECT_RATE_STOP}, it means the sensor
911  *         does not support direct report.
912  */
913 int ASensor_getHighestDirectReportRateLevel (const(ASensor)* sensor);
914 /* __ANDROID_API__ >= 26 */
915 
916 /**
917  * Returns the sensor's handle.
918  *
919  * The handle identifies the sensor within the system and is included in the
920  * {@link ASensorEvent#sensor} field of sensor events, including those sent with type
921  * {@link ASENSOR_TYPE_ADDITIONAL_INFO}.
922  *
923  * A sensor's handle is able to be used to map {@link ASENSOR_TYPE_ADDITIONAL_INFO} events to the
924  * sensor that generated the event.
925  *
926  * It is important to note that the value returned by {@link ASensor_getHandle} is not the same as
927  * the value returned by the Java API {@link android.hardware.Sensor#getId} and no mapping exists
928  * between the values.
929  */
930 int ASensor_getHandle (const(ASensor)* sensor);
931 /* __ANDROID_API__ >= ANDROID_API_Q__ */
932 
933 // ANDROID_SENSOR_H
934 
935 /** @} */